/*
* @author : TF-BJ-C064
* @creation : 2014-7-17 下午7:34:57
* @description : 
*
*/

package com.base;

import org.springframework.util.Assert;

public class DataSourceSwitcher {
	@SuppressWarnings("rawtypes")
	private static final ThreadLocal contextHolder = new ThreadLocal();

	@SuppressWarnings("unchecked")
	public static void setDataSource(String dataSource) {
		Assert.notNull(dataSource, "dataSource cannot be null");
		contextHolder.set(dataSource);
	}

	public static void setMaster(){
		clearDataSource();
    }
	
	public static void setSlave() {
		setDataSource("slave");
	}
	
	public static String getDataSource() {
		return (String) contextHolder.get();
	}

	public static void clearDataSource() {
		contextHolder.remove();
	}
}

